<template>
	<view class="tabbar" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
		<view class="tabbar-item" v-for="(item, index) in list" :key="index" @click="tabbarChange(item.pagePath)">
			<image class="item-img" :src="item.selectedIconPath" v-if="current == index"></image>
			<image class="item-img" :src="item.iconPath" v-else></image>
			<view class="item-name" :class="{'tabbarActive': current == index}" v-if="item.text">{{item.text}}
			</view>
			<view class="box flexleft" v-if="index==3">
				<u-badge max="99" :value="total_num"></u-badge>
			</view>
			<view class="box flexleft" v-if="index==4">
				<u-badge max="99" :value="total_noread_num"></u-badge>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		name: "tabbarxsd",
		components: {},
		props: ['current'],
		data() {
			return {
				paddingBottomHeight: 0, //苹果X以上手机底部适配高度
				list: [{
					"text": "首頁",
					"pagePath": "/pages/index/index",
					"iconPath": "/static/images/tabbar/tab1.png",
					"selectedIconPath": "/static/images/tabbar/tab1_active.png"
				}, {
					"text": "跑腿",
					"pagePath": "/pages/runErrands/runErrands",
					"iconPath": "/static/images/tabbar/tab2.png",
					"selectedIconPath": "/static/images/tabbar/tab2_active.png"
				}, {
					"text": "掃碼",
					"pagePath": "/pages/scanpage/scanpage",
					"iconPath": "/static/images/tabbar/scan.png",
					"selectedIconPath": "/static/images/tabbar/scans.png"
				}, {
					"text": "訂單",
					"pagePath": "/pages/order/order",
					"iconPath": "/static/images/tabbar/tab3.png",
					"selectedIconPath": "/static/images/tabbar/tab3_active.png"
				}, {
					"text": "消息",
					"pagePath": "/pages/message/message",
					"iconPath": "/static/images/tabbar/tab4.png",
					"selectedIconPath": "/static/images/tabbar/tab4_active.png"
				}, {
					"text": "我的",
					"pagePath": "/pages/mine/mine",
					"iconPath": "/static/images/tabbar/tab5.png",
					"selectedIconPath": "/static/images/tabbar/tab5_active.png"
				}],
				total_num: 0,
				total_noread_num: 0
			}
		},
		created() {
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
					model.forEach(item => {
						//适配iphoneX以上的底部，给tabbar一定高度的padding-bottom
						if (res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
							that.paddingBottomHeight = 0;
						}
					})
				}
			});
		},
		methods: {
			init() {
				if (this.http.checkIsLogin()) {
					httpRequest.request('/api/user/getOrderTotalData', 'GET', {
					}).then(res => {
						this.total_num = res.data.total_num
						this.total_noread_num = res.data.total_noread_num
					})
				}
			},
			tabbarChange(path) {
				uni.switchTab({
					url: path
				})
			}
		}

	}
</script>

<style lang="scss">
	.item-img {
		height: 40rpx;
		width: 40rpx;
		margin: auto;
		display: block;
	}

	.box {
		position: absolute;
		top: -10rpx;
		right: 30rpx;
	}

	// .fabuimg{
	// 	position: absolute;
	// 	bottom: 36rpx;
	// 	left: 10rpx;
	// 	height: 90rpx;
	// 	width: 90rpx;
	// 	margin: auto;
	// 	display: block;
	// 	background-color: #fff;
	// 	background-size: 80rpx 80rpx;
	// 	border-radius: 50%;
	// 	// box-shadow: 0px -5px 5px 0px rgba(0, 0, 0, 0.05);
	// }

	.tabbar {
		display: flex;
		justify-content: space-around;
		align-items: flex-end;
		background: #FFFFFF;
		border-radius: 0rpx;
		/* #ifdef MP-WEIXIN */
		height: 140rpx;
		/* #endif */
		/* #ifdef H5 */
		height: 140rpx;
		/* #endif */
		/* #ifdef APP-PLUS */
		height: 140rpx;
		/* #endif */
		padding: 0;
		box-sizing: border-box;
		position: fixed;
		width: 100%;
		bottom: 0;
		overflow: inherit;
		z-index: 100;
		// box-shadow: 0px -2px 4px 1px rgba(0, 0, 0, 0.05);
	}

	.tabbar-item {
		margin-bottom: 30rpx;
		width: 250rpx;
		position: relative;
	}

	.item-name {
		font-size: 24rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		text-align: center;
		color: #999999;
		margin-top: 14rpx;
	}

	.tabbarActive {
		color: #feb800;
		text-align: center;
	}
</style>